package com.example.hearthstoneagain;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.os.Build;

public class MainDeckActivity extends ActionBarActivity {
	
	Context context;
	
	ListView lst;
	
	List<HashMap<String,String>> listaclasses;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_deck);

		context = this.getApplicationContext();
		
		lst = (ListView) this.findViewById(R.id.listView2);
		
		String[] from = { "flag","txt" };

		int[] to = { R.id.flag,R.id.txt};
		
		listaclasses = listaclasses();
		
		CustomAdapter adapter = new CustomAdapter(getBaseContext(), listaclasses, R.layout.listview_layout, from, to);
		
		lst.setAdapter(adapter);
		
		lst.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				
				BancodeDados banco = new BancodeDados(context);
				
				HashMap<String, String> hm = (HashMap<String, String>) lst.getAdapter().getItem(arg2);
				
				String nomeclasse = hm.get("txt");
				
				Intent intent = new Intent (MainDeckActivity.this,DeckSelectionActivity.class);
				intent.putExtra("classe", nomeclasse);
				
				TabGroupActivity parentActivity = (TabGroupActivity)getParent();
				parentActivity.startChildActivity("DeckSelectionActivity", intent);
				
				//startActivity(intent);
			}
		});
		
		
		
	}
	
	
	
	
	
	public List<HashMap<String,String>> listaclasses() {
		
		List<HashMap<String,String>> listaretorno = new ArrayList<HashMap<String,String>>();
		
		HashMap<String, String> druid = new HashMap<String,String>();
		druid.put("txt","Druid");
		druid.put("flag",Integer.toString(R.drawable.druid));
		listaretorno.add(druid);
		
		HashMap<String, String> hunter = new HashMap<String,String>();
		hunter.put("txt","Hunter");
		hunter.put("flag",Integer.toString(R.drawable.hunter));
		listaretorno.add(hunter);
		
		HashMap<String, String> mage = new HashMap<String,String>();
		mage.put("txt","Mage");
		mage.put("flag",Integer.toString(R.drawable.mage));
		listaretorno.add(mage);
		
		HashMap<String, String> paladin = new HashMap<String,String>();
		paladin.put("txt","Paladin");
		paladin.put("flag",Integer.toString(R.drawable.paladin));
		listaretorno.add(paladin);
		
		HashMap<String, String> priest = new HashMap<String,String>();
		priest.put("txt","Priest");
		priest.put("flag",Integer.toString(R.drawable.priest));
		listaretorno.add(priest);
		
		HashMap<String, String> rogue = new HashMap<String,String>();
		rogue.put("txt","Rogue");
		rogue.put("flag",Integer.toString(R.drawable.rogue));
		listaretorno.add(rogue);
		
		HashMap<String, String> shaman = new HashMap<String,String>();
		shaman.put("txt","Shaman");
		shaman.put("flag",Integer.toString(R.drawable.shaman));
		listaretorno.add(shaman);
		
		HashMap<String, String> lock = new HashMap<String,String>();
		lock.put("txt","Warlock");
		lock.put("flag",Integer.toString(R.drawable.warlock));
		listaretorno.add(lock);
		
		HashMap<String, String> warrior = new HashMap<String,String>();
		warrior.put("txt","Warrior");
		warrior.put("flag",Integer.toString(R.drawable.warrior));
		listaretorno.add(warrior);
		
		return listaretorno;
	}
	
	
	
	
}
